<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button class="add">添加</button>
  <table border="1" cellspacing="0" cellpadding="10">
    <tr>
      <th>姓名</th>
      <th>操作</th>
    </tr>

  </table>

  <script>
    let addBtn = document.querySelector(".add");
    let tbody = document.querySelector("tbody")
    addBtn.addEventListener("click", () => {
      tbody.innerHTML += `<tr>
      <td>${new Date().toTimeString()}</td>
      <td><button class="delItem">删除</button></td>
    </tr>`
    })

    tbody.addEventListener("click", () => {
      // console.log(event);
      // 事件委托
      if (event.target.classList.contains("delItem")) {
        event.target.parentElement.parentElement.remove();
      }

      if (event.target.classList.contains("showItem")) {
        console.log("展开子信息");
      }
    })

  </script>
</body>

</html>